﻿using ServerFramework.Tools;

namespace ServerFramework.Net.Tcp
{
    /// <summary>
    /// rpc 服务器
    /// </summary>
    public class RpcServer : Rpc
    {
        protected TcpServer _server;
        public RpcServer(int numConnections)
        {
            _server = new TcpServer(numConnections);
            _server.onRecvMessage += RpcRecv;
        }
        public void Start(int port, string ip = "")
        {
            _server.Start(port, ip);
        }
        protected override void RpcSend(ISender sender,RpcRequst requst)
        {
            if (sender != null)
            {
                sender.Send(requst.Pack());
            }
            else
            {
                Log.WriteLog(ELogLevel.LOG_ERROR, "rpc sender is null");   
            }
        }

        public void Close()
        {
            if (_server != null)
            {
                _server.Close();
            }
        }
    }
}
